package com.mobile.clouree;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
import com.example.androidane.R;

public class AndroidAneSetNotifyContent implements FREFunction {

	private final static String PRESS_NAME = "MessageTypeSettings";
	private final static String PRESS_KEY_WAKE = "MsgWake";
	@Override
	public FREObject call(FREContext arg0, FREObject[] arg1) {
		try
		{
//			load
		 String msg = arg1[0].getAsString();
		 String titleMsg =arg1[1].getAsString();
		 SharedPreferences settings = arg0.getActivity().getSharedPreferences(PRESS_NAME, 0);
		 boolean isWake = settings.getBoolean(PRESS_KEY_WAKE, false);
//		 notify
		 NotificationManager nm = (NotificationManager)arg0.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
		 Notification notify = new Notification(R.drawable.ic_launcher,msg,System.currentTimeMillis());
		 notify.flags = Notification.FLAG_AUTO_CANCEL;
		 int notifyDefault = 0;
		 if(isWake)
		 {
			 notifyDefault = Notification.DEFAULT_VIBRATE; 
		 }else
		 {
			 notifyDefault = Notification.DEFAULT_ALL; 
		 }
		 notify.defaults = notifyDefault;
		 
		 Intent it = new Intent();
		 PendingIntent pi = PendingIntent.getActivity(arg0.getActivity(), 0, it, 0);
		 notify.setLatestEventInfo(arg0.getActivity(), titleMsg, msg, pi);
		 nm.notify(1, notify);
		}catch (Exception e)
		{
			
		}
		return null;
	}

}
